<template>
    <Teleport to="body">
        <div class="toast-wrapper">
            <div class="toast" :class="type">
                <span class="icon" :class="type"></span>
                <div class="content">{{ message }}</div>
            </div>
        </div>
    </Teleport>
</template>

<script setup>
const props = defineProps({
    message: String,
    type: {
        type: String,
        default: 'info'
    },
    duration: {
        type: Number,
        default: 3000
    }
})

</script>

<style scoped>
.toast-wrapper {
    position: fixed;
    top: 24px;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    pointer-events: none;
    z-index: 9999;
}

.toast {
    display: inline-flex;
    align-items: center;
    padding: 12px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    color: white;
    font-size: 14px;
    line-height: 1.5;
    max-width: 80vw;
    pointer-events: auto;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.27, 1.55);
    animation: slideDown 0.4s forwards;
}

.toast .icon {
    width: 20px;
    height: 20px;
    margin-right: 12px;
    background-size: contain;
    background-repeat: no-repeat;
}

.toast .content {
    flex: 1;
    padding-right: 12px;
}

.toast .close-btn {
    cursor: pointer;
    font-size: 18px;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.toast .close-btn:hover {
    opacity: 1;
}

/* 类型配色方案 */
.toast.info {
    background: linear-gradient(135deg, #4492d3, #5cabff);
}

.toast.success {
    background: linear-gradient(135deg, #4CAF50, #66BB6A);
}

.toast.error {
    background: linear-gradient(135deg, #F44336, #EF5350);
}

.toast.warning {
    background: linear-gradient(135deg, #FF9800, #FFA726);
}

/* 图标方案 */
.toast .icon.info {
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3e%3cpath d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z'/%3e%3c/svg%3e");
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-40px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* 消失动画 */
.toast-leave-active {
    animation: slideUp 0.3s forwards;
}

@keyframes slideUp {
    to {
        opacity: 0;
        transform: translateY(-20px) scale(0.9);
    }
}
</style>
